<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="司机姓名" prop="driverName">
        <el-input
          v-model="queryParams.driverName"
          placeholder="请输入司机姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="contactMobile">
        <el-input
          v-model="queryParams.contactMobile"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--el-form-item label="所属单位" prop="driverCompany">
        <el-input
          v-model="queryParams.driverCompany"
          placeholder="请输入所属单位/个人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="identityCardNumber">
        <el-input
          v-model="queryParams.identityCardNumber"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item-->
      <!--el-form-item label="身份证长期，是或否" prop="identityCardLimit">
        <el-select v-model="queryParams.identityCardLimit" placeholder="请选择身份证长期，是或否" clearable>
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item-->
      <!--el-form-item label="身份证有效期">
        <el-date-picker
          v-model="daterangeIdentityExpirationDate"
          style="width: 205px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input
          v-model="queryParams.age"
          placeholder="请输入年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职位" prop="post">
        <el-input
          v-model="queryParams.post"
          placeholder="请输入职位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.employee_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="驾驶证号" prop="driverLicenseNumber">
        <el-input
          v-model="queryParams.driverLicenseNumber"
          placeholder="请输入驾驶证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="驾驶证档案号" prop="driverArchiveNumber">
        <el-input
          v-model="queryParams.driverArchiveNumber"
          placeholder="请输入驾驶证档案号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="准驾车型" prop="approveDriveModel">
        <el-select v-model="queryParams.approveDriveModel" placeholder="请选择准驾车型" clearable>
          <el-option
            v-for="dict in dict.type.drive_model"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="驾驶证发证机关" prop="licenseIssueAuthority">
        <el-input
          v-model="queryParams.licenseIssueAuthority"
          placeholder="请输入驾驶证发证机关"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="驾照起始日期">
        <el-date-picker
          v-model="daterangeLicenseBeginDate"
          style="width: 205px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="驾照长期，是或否" prop="licenseLimit">
        <el-select v-model="queryParams.licenseLimit" placeholder="请选择驾照长期，是或否" clearable>
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="驾照结束日期">
        <el-date-picker
          v-model="daterangeLicenseEndDate"
          style="width: 205px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="道路运输从业证" prop="roadTransportCertificate">
        <el-input
          v-model="queryParams.roadTransportCertificate"
          placeholder="请输入道路运输从业证"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省code" prop="provinceCode">
        <el-input
          v-model="queryParams.provinceCode"
          placeholder="请输入省code"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省名称" prop="provinceName">
        <el-input
          v-model="queryParams.provinceName"
          placeholder="请输入省名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市code" prop="cityCode">
        <el-input
          v-model="queryParams.cityCode"
          placeholder="请输入市code"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市名称" prop="cityName">
        <el-input
          v-model="queryParams.cityName"
          placeholder="请输入市名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区code" prop="areaCode">
        <el-input
          v-model="queryParams.areaCode"
          placeholder="请输入区code"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区名称" prop="areaName">
        <el-input
          v-model="queryParams.areaName"
          placeholder="请输入区名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item-->
      <!--el-form-item label="司机业务" prop="driverWork">
        <el-select v-model="queryParams.driverWork" placeholder="请选择司机业务" clearable>
          <el-option
            v-for="dict in dict.type.work_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="司机标记" prop="driverMark">
        <el-select v-model="queryParams.driverMark" placeholder="请选择司机标记" clearable>
          <el-option
            v-for="dict in dict.type.driver_mark"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item-->
      <!--el-form-item label="备注" prop="remark">
        <el-input
          v-model="queryParams.remark"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="园区代码" prop="parkCode">
        <el-input
          v-model="queryParams.parkCode"
          placeholder="请输入园区代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item-->
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 205px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['drivers:driver:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['drivers:driver:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['drivers:driver:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['drivers:driver:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" @computeTable="computeTableHeight"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="driverList" @selection-change="handleSelectionChange" border :height="tableHeight" :row-style="{height:'35px'}" :cell-style="{padding:'0px'}">
      <el-table-column type="selection" width="45" align="center" />
      <el-table-column type="index" prop="" width="55" label="序号" align="center" >
        <template slot-scope="scope">
          <span>{{ scope.$index+1 +(queryParams.pageNum-1)*queryParams.pageSize }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100%">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['drivers:driver:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['drivers:driver:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
      <!--el-table-column label="司机ID" align="center" prop="driverId" /-->
      <el-table-column label="司机姓名" align="center" prop="driverName" />
      <!--el-table-column label="联系电话" align="center" prop="contactMobile"  width="110" /-->
      <!--el-table-column label="所属单位/个人" align="center" prop="driverCompany"  width="120" :show-overflow-tooltip="true" /-->
      <el-table-column label="身份证号" align="center" prop="identityCardNumber" width="180" />
      <!--el-table-column label="身份证长期" align="center" prop="identityCardLimit" width="100" />
      <el-table-column label="身份证有效期" align="center" prop="identityExpirationDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.identityExpirationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column-->
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="联系电话" align="center" prop="contactMobile"  width="110" />
      <el-table-column label="职位" align="center" prop="post" />
      <el-table-column label="员工状态" align="center" prop="status" />
      <!--el-table-column label="驾驶证号" align="center" prop="driverLicenseNumber" width="180" />
      <el-table-column label="驾驶证档案号" align="center" prop="driverArchiveNumber" width="120" />
      <el-table-column label="准驾车型" align="center" prop="approveDriveModel" />
      <el-table-column label="驾驶证发证机关" align="center" prop="licenseIssueAuthority" width="180" :show-overflow-tooltip="true" />
      <el-table-column label="驾照起始日期" align="center" prop="licenseBeginDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.licenseBeginDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="驾照长期" align="center" prop="licenseLimit" />
      <el-table-column label="驾照结束日期" align="center" prop="licenseEndDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.licenseEndDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="道路运输从业证" align="center" prop="roadTransportCertificate" width="180" /-->
      <!--el-table-column label="省code" align="center" prop="provinceCode" />
      <el-table-column label="省名称" align="center" prop="provinceName" />
      <el-table-column label="市code" align="center" prop="cityCode" />
      <el-table-column label="市名称" align="center" prop="cityName" />
      <el-table-column label="区code" align="center" prop="areaCode" />
      <el-table-column label="区名称" align="center" prop="areaName" /-->
      <!--el-table-column label="司机业务" align="center" prop="driverWork" />
      <el-table-column label="司机标记" align="center" prop="driverMark" /-->
      <el-table-column label="备注" align="center" prop="remark" width="180" :show-overflow-tooltip="true" />
      <!--el-table-column label="身份证照片面" align="center" prop="identityPhotoPicture" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.identityPhotoPicture" :width="50" :height="25"/>
        </template>
      </el-table-column>
      <el-table-column label="身份证国徽面" align="center" prop="identityBadgePicture" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.identityBadgePicture" :width="50" :height="25"/>
        </template>
      </el-table-column>
      <el-table-column label="驾驶证正面" align="center" prop="licenseFrontPicture" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.licenseFrontPicture" :width="50" :height="25"/>
        </template>
      </el-table-column>
      <el-table-column label="驾驶证反面" align="center" prop="licenseBackPicture" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.licenseBackPicture" :width="50" :height="25"/>
        </template>
      </el-table-column>
      <el-table-column label="从业资格证" align="center" prop="roadTransportPicture" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.roadTransportPicture" :width="50" :height="25"/>
        </template>
      </el-table-column-->
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改司机信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="司机姓名" prop="driverName">
          <el-input v-model="form.driverName" placeholder="请输入司机姓名" clearable />
        </el-form-item>
        <!--el-form-item label="联系电话" prop="contactMobile">
          <el-input v-model="form.contactMobile" placeholder="请输入联系电话" clearable />
        </el-form-item-->
        <!--el-form-item label="所属单位/个人" prop="driverCompany">
          <el-input v-model="form.driverCompany" placeholder="请输入所属单位/个人" clearable />
        </el-form-item-->
        <el-form-item label="身份证号" prop="identityCardNumber">
          <el-input v-model="form.identityCardNumber" placeholder="请输入身份证号" clearable />
        </el-form-item>
        <!--el-form-item label="身份证长期" prop="identityCardLimit">
          <el-radio-group v-model="form.identityCardLimit">
            <el-radio
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="身份证有效期" prop="identityExpirationDate">
          <el-date-picker clearable
            v-model="form.identityExpirationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择身份证有效期"
            style="width: 340px;">
          </el-date-picker>
        </el-form-item-->
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别" style="width: 340px;" clearable>
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" clearable />
        </el-form-item>
        <el-form-item label="联系电话" prop="contactMobile">
          <el-input v-model="form.contactMobile" placeholder="请输入联系电话" clearable />
        </el-form-item>
        <el-form-item label="职位" prop="post">
          <el-input v-model="form.post" placeholder="请输入职位" clearable />
        </el-form-item>
        <el-form-item label="员工状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态" style="width: 340px;" clearable>
            <el-option
              v-for="dict in dict.type.employee_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <!--el-form-item label="驾驶证号" prop="driverLicenseNumber">
          <el-input v-model="form.driverLicenseNumber" placeholder="请输入驾驶证号" clearable />
        </el-form-item>
        <el-form-item label="驾驶证档案号" prop="driverArchiveNumber">
          <el-input v-model="form.driverArchiveNumber" placeholder="请输入驾驶证档案号" clearable />
        </el-form-item>
        <el-form-item label="准驾车型" prop="approveDriveModel">
          <el-select v-model="form.approveDriveModel" placeholder="请选择准驾车型" style="width: 340px;" clearable>
            <el-option
              v-for="dict in dict.type.drive_model"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="驾驶证发证" prop="licenseIssueAuthority">
          <el-input v-model="form.licenseIssueAuthority" placeholder="请输入驾驶证发证机关" clearable />
        </el-form-item>
        <el-form-item label="驾照起始日期" prop="licenseBeginDate">
          <el-date-picker clearable
            v-model="form.licenseBeginDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择驾照起始日期"
            style="width: 340px;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="驾照长期" prop="licenseLimit">
          <el-radio-group v-model="form.licenseLimit" @change="handlerChangeLicenseLimit">
            <el-radio
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.label"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="驾照结束日期" prop="licenseEndDate">
          <el-date-picker clearable
            v-model="form.licenseEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择驾照结束日期"
            style="width: 340px;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="运输从业证" prop="roadTransportCertificate">
          <el-input v-model="form.roadTransportCertificate" placeholder="请输入道路运输从业证" clearable />
        </el-form-item-->
        <!--- 省市区联动 :default="selectedOptions" prop="selectedOptions" -->
        <!--el-form-item label="行政区域" prop="selectedOptions">
          <el-cascader :options="regionData" v-model="selectedOptions" @change="handleChangeRegion"  v-if="open"/> 
        </el-form-item-->
        <!--el-form-item label="省code" prop="provinceCode">
          <el-input v-model="form.provinceCode" placeholder="请输入省code" clearable />
        </el-form-item>
        <el-form-item label="省名称" prop="provinceName">
          <el-input v-model="form.provinceName" placeholder="请输入省名称" clearable />
        </el-form-item>
        <el-form-item label="市code" prop="cityCode">
          <el-input v-model="form.cityCode" placeholder="请输入市code" clearable />
        </el-form-item>
        <el-form-item label="市名称" prop="cityName">
          <el-input v-model="form.cityName" placeholder="请输入市名称" clearable />
        </el-form-item>
        <el-form-item label="区code" prop="areaCode">
          <el-input v-model="form.areaCode" placeholder="请输入区code" clearable />
        </el-form-item>
        <el-form-item label="区名称" prop="areaName">
          <el-input v-model="form.areaName" placeholder="请输入区名称" clearable />
        </el-form-item-->
        <!--el-form-item label="司机业务" prop="driverWork">
          <el-select v-model="form.driverWork" placeholder="请选择司机业务"  clearable>
            <el-option
              v-for="dict in dict.type.work_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="司机标记" prop="driverMark">
          <el-select v-model="form.driverMark" placeholder="请选择司机标记"  clearable>
            <el-option
              v-for="dict in dict.type.driver_mark"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            ></el-option>
          </el-select>
        </el-form-item-->
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" clearable />
        </el-form-item>
        <!--div class="dashed-line" />
        <el-form-item label="身份证照片面" prop="identityPhotoPicture">
          <image-upload v-model="form.identityPhotoPicture" :limit="1"/>
        </el-form-item>
        <el-form-item label="身份证国徽面" prop="identityBadgePicture">
          <image-upload v-model="form.identityBadgePicture" :limit="1"/>
        </el-form-item>
        <el-form-item label="驾驶证正面" prop="licenseFrontPicture">
          <image-upload v-model="form.licenseFrontPicture" :limit="1"/>
        </el-form-item>
        <el-form-item label="驾驶证反面" prop="licenseBackPicture">
          <image-upload v-model="form.licenseBackPicture" :limit="1"/>
        </el-form-item>
        <el-form-item label="道路运输从业资格证" prop="roadTransportPicture">
          <image-upload v-model="form.roadTransportPicture" :limit="1"/>
        </el-form-item-->
        <!--el-form-item label="园区代码" prop="parkCode">
          <el-input v-model="form.parkCode" placeholder="请输入园区代码" clearable />
        </el-form-item-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDriver, getDriver, delDriver, addDriver, updateDriver } from "@/api/drivers/driver";
import { regionData, codeToText } from 'element-china-area-data';

export default {
  name: "Driver",
  dicts: ['drive_model', 'employee_status', 'sys_yes_no', 'work_type', 'sys_user_sex', 'driver_mark'],
  data() {
    return {
      // 定义列表高度
      tableHeight: 430,
      // 定义查询高度
      queryHeight: 200,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 司机信息表格数据
      driverList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 园区代码时间范围
      daterangeIdentityExpirationDate: [],
      // 园区代码时间范围
      daterangeLicenseBeginDate: [],
      // 园区代码时间范围
      daterangeLicenseEndDate: [],
      // 园区代码时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        driverName: null,
        contactMobile: null,
        driverCompany: null,
        identityCardNumber: null,
        identityCardLimit: null,
        identityExpirationDate: null,
        sex: null,
        age: null,
        post: null,
        status: null,
        driverLicenseNumber: null,
        driverArchiveNumber: null,
        approveDriveModel: null,
        licenseIssueAuthority: null,
        licenseBeginDate: null,
        licenseLimit: null,
        licenseEndDate: null,
        roadTransportCertificate: null,
        provinceCode: null,
        provinceName: null,
        cityCode: null,
        cityName: null,
        areaCode: null,
        areaName: null,
        driverWork: null,
        driverMark: null,
        remark: null,
        identityPhotoPicture: null,
        identityBadgePicture: null,
        licenseFrontPicture: null,
        licenseBackPicture: null,
        roadTransportPicture: null,
        parkCode: null,
        createBy: null,
        createTime: null,
      },
      // 省市区
      regionData,
      selectedOptions: [],
      codeToText,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        driverName: [
          { required: true, message: "司机姓名不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    this.$nextTick(() =>{
      // 根据浏览器高度设置初始高度 - 按钮行高度28 - 页码行高度28 - （面包屑+TAB行）高度160
      this.queryHeight = this.$refs.queryForm.$el.offsetHeight;
      this.tableHeight = window.innerHeight - this.$refs.queryForm.$el.offsetHeight - 28 - 28 - 160;
      // 监听浏览器高度变化，改变表格高度
      window.onresize = () =>{
        this.tableHeight = window.innerHeight - this.$refs.queryForm.$el.offsetHeight - 28 - 28 - 160;
      }
    })
  },
  methods: {
    /** 查询司机信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeIdentityExpirationDate && '' != this.daterangeIdentityExpirationDate) {
        this.queryParams.params["beginIdentityExpirationDate"] = this.daterangeIdentityExpirationDate[0];
        this.queryParams.params["endIdentityExpirationDate"] = this.daterangeIdentityExpirationDate[1];
      }
      if (null != this.daterangeLicenseBeginDate && '' != this.daterangeLicenseBeginDate) {
        this.queryParams.params["beginLicenseBeginDate"] = this.daterangeLicenseBeginDate[0];
        this.queryParams.params["endLicenseBeginDate"] = this.daterangeLicenseBeginDate[1];
      }
      if (null != this.daterangeLicenseEndDate && '' != this.daterangeLicenseEndDate) {
        this.queryParams.params["beginLicenseEndDate"] = this.daterangeLicenseEndDate[0];
        this.queryParams.params["endLicenseEndDate"] = this.daterangeLicenseEndDate[1];
      }
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listDriver(this.queryParams).then(response => {
        this.driverList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        driverId: null,
        driverName: null,
        contactMobile: null,
        driverCompany: null,
        identityCardNumber: null,
        identityCardLimit: null,
        identityExpirationDate: null,
        sex: null,
        age: null,
        post: null,
        status: null,
        driverLicenseNumber: null,
        driverArchiveNumber: null,
        approveDriveModel: null,
        licenseIssueAuthority: null,
        licenseBeginDate: null,
        licenseLimit: null,
        licenseEndDate: null,
        roadTransportCertificate: null,
        provinceCode: null,
        provinceName: null,
        cityCode: null,
        cityName: null,
        areaCode: null,
        areaName: null,
        driverWork: null,
        driverMark: null,
        remark: null,
        identityPhotoPicture: null,
        identityBadgePicture: null,
        licenseFrontPicture: null,
        licenseBackPicture: null,
        roadTransportPicture: null,
        dataRealm: null,
        parkCode: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeIdentityExpirationDate = [];
      this.daterangeLicenseBeginDate = [];
      this.daterangeLicenseEndDate = [];
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.driverId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.selectedOptions[0] = '';
      this.selectedOptions[1] = '';
      this.selectedOptions[2] = '';
      this.open = true;
      this.title = "添加司机信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const driverId = row.driverId || this.ids
      getDriver(driverId).then(response => {
        this.form = response.data;
        this.selectedOptions[0] = response.data.provinceCode;
        this.selectedOptions[1] = response.data.cityCode;
        this.selectedOptions[2] = response.data.areaCode;
        this.open = true;
        this.title = "修改司机信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
//      console.log('this.form', this.form);
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.driverId != null) {
            updateDriver(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDriver(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const driverIds = row.driverId || this.ids;
      this.$modal.confirm('是否确认删除司机信息编号为"' + driverIds + '"的数据项？').then(function() {
        return delDriver(driverIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('drivers/driver/export', {
        ...this.queryParams
      }, `司机信息_${this.parseTime(new Date(), '{y}{m}{d}_{h}{i}')}.xlsx`)
    },
    computeTableHeight(){
      if( this.showSearch==true ){
        this.tableHeight = window.innerHeight - this.queryHeight - 28 - 28 - 160;
      } else {
        this.tableHeight = window.innerHeight - 28 - 28 - 160;
      }
    },
    /** 省市区选择 **/
    handleChangeRegion(value) {
//      console.log('handleChangeRegion.value', value);
//      console.log('handleChange.selectedOptions', this.selectedOptions);
//      console.log('this.selectedOptions[0]', this.selectedOptions[0]);
//      console.log('this.selectedOptions[1]', this.selectedOptions[1]);
//      console.log('this.selectedOptions[2]', this.selectedOptions[2]);
//      console.log('provinceName', this.codeToText[this.selectedOptions[0]]);
//      console.log('cityName', this.codeToText[this.selectedOptions[1]]);
//      console.log('areaName', this.codeToText[this.selectedOptions[2]]);

      this.form.provinceCode = this.selectedOptions[0];
      this.form.cityCode = this.selectedOptions[1];
      this.form.areaCode = this.selectedOptions[2];
      this.form.provinceName = this.codeToText[this.selectedOptions[0]];
      this.form.cityName = this.codeToText[this.selectedOptions[1]];
      this.form.areaName = this.codeToText[this.selectedOptions[2]];
  /**/   
      //对象加了一个属性，在控制台能打印出来，但是却没有更新到视图上时，也许这个时候就需要用到this.$set（）这个方法了
      //向响应式对象中添加一个属性，并确保这个新属性同样是响应式的，且触发视图更新。它必须用于向响应式对象上添加新属性，因为 Vue 无法探测普通的新增属性
      //调用方法: Vue.set( target , key , value)
      //target: 要更改的数据源（可以是一个对象或者数组）
      //key 要更改的具体数据 （索引）
      //value 重新赋的值
//      this.$set(this.form, 'xname', this.codeToText[value[0]]);
    },
    handlerChangeCardLimit() {
//      console.log('handlerChangeCardLimit');
//      console.log('handlerChangeCardLimit', this.form.identityExpirationDate);
      this.form.identityExpirationDate ='';
//      console.log('handlerChangeCardLimit', this.form.identityExpirationDate);
    },
    handlerChangeLicenseLimit() {
      this.form.licenseEndDate ='';
    },
  }
};
</script>

<style scoped lang='less'>
/*/deep/的意思大概为深入的，深远的。Scoped CSS规范是Web组件产生不污染其他组件，也不被其他组件污染的CSS规范。*/
/*在打包的时候会生成一个独一无二hash值，这样父组件的样式就不会影响到子组件了，要想修改子组件的样式，*/
/*一般是提取一个公共文件，在公共文件里面修改样式.提取公共文件的方式来修改，以达到自己想要的，但是同时其他地方也会受到影响*/
/*需要有一个方法或者方式，既不影响到别的地方，又能修改子组件在当前的样式。*/
/deep/.color-date-danger{
  background: red;
}
/deep/.color-date-warning{
  background: rgb(255, 255, 0);
}

</style>


<style scoped lang='less'>
/* 横线 */
.dashed-line{
  border-top: 2px dashed #cac7c7; /* 虚线的宽度、样式和颜色 */
  width: 90%;
  height: 1px;
  margin-left: 40px;
  margin-top: -0.50em;
  margin-bottom: 0.75em;
//  margin:0 auto;
  position: relative;
  text-align: center;
}

//.dashed-line {
//  border-top: 2px dashed #000; /* 虚线的宽度、样式和颜色 */
//  width: 100%; /* 虚线的长度 */
//  margin: 10px 0; /* 虚线的上下间距 */
//}

.el-picker {
  width: 200px !important;
}
.el-select{
  width: 200px;
}
/*.el-input{
  width: 200px;
}*/
.el-cascader{
  width: 200px;
}
.el-radio-group{
  width: 200px;
}
.address{
  width: 510px;
}
.remark{
  width: 510px;
}
</style>